/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:
 * Date: 2024-11-13
 * Time: 20:55
 */
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();
        //利用数组进行排序
        double[] weights = new double[N];
        for (int i = 0; i < N; i++) {
            weights[i] = scanner.nextDouble();
        }
        scanner.close();

        // 对鸡蛋重量进行排序
        Arrays.sort(weights);

        // 初始化最小差值和最大总重量
        double minDifference = Double.MAX_VALUE;
        double maxTotalWeight = 0;

        // 遍历所有可能的M个鸡蛋的组合
        for (int i = 0; i <= N - M; i++) {
            // 计算当前组合的重量差值
            double difference = weights[i + M - 1] - weights[i];
            // 如果当前差值小于最小差值，则更新最小差值和最大总重量
            if (difference < minDifference) {
                minDifference = difference;
                maxTotalWeight = 0;
                for (int j = i; j < i + M; j++) {
                    maxTotalWeight += weights[j];
                }
            }
            // 如果当前差值等于最小差值，则更新最大总重量
            else if (difference == minDifference) {
                double currentTotalWeight = 0;
                for (int j = i; j < i + M; j++) {
                    currentTotalWeight += weights[j];
                }
                if (currentTotalWeight > maxTotalWeight) {
                    maxTotalWeight = currentTotalWeight;
                }
            }
        }

        // 输出符合条件的最重一盒鸡蛋的总重量，保留两位小数
        System.out.printf("%.2f\n", maxTotalWeight);
    }


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        double weights[] = new double[N];
        for (int i = 0; i < N; i++) {
            weights[i] = sc.nextDouble();
        }

        sc.close();

        Arrays.sort(weights);

        double minDifference = Double.MAX_VALUE;
        double maxTotalWeights = 0;

        for (int i = 0; i < N-M; i++) {
            double difference = weights[i+M-1] - weights[i];
            if(difference < minDifference){
                minDifference = difference;
                maxTotalWeights = 0;
                for (int j = i; j < M+i; j++) {
                    maxTotalWeights += weights[j];
                }
            }
            else if(difference == minDifference){
                double currentTotalWeight = 0;
                for (int j = i; j < i+M; j++) {
                    currentTotalWeight += weights[j];
                }
                if(currentTotalWeight > maxTotalWeights){
                    maxTotalWeights = currentTotalWeight;
                }
            }
        }
        System.out.println(maxTotalWeights);
    }
}